﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.Serialization;

namespace Metro.Kashikoi.ServiceContract.Location
{
    /// <summary>
    /// This class defines the organization.
    /// </summary>
    [DataContract(IsReference = true)]
    public class Organization : Region
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Organization"/> class.
        /// </summary>
        public Organization()
        {
            Address = new Address();
        }

        /// <summary>
        /// Gets or sets the address.
        /// </summary>
        /// <value>
        /// The address.
        /// </value>
        [DataMember]
        public Address Address { get; set; }

        /// <summary>
        /// Gets or sets the facilities.
        /// </summary>
        /// <value>
        /// The facilities.
        /// </value>
        [NotMapped]
        public IEnumerable<Facility> Facilities
        {
            get
            {
                if (this.Children != null)
                {
                    return this.Children.OfType<Facility>();
                }
                return null;
            }
            set
            {
                if (this.Children == null)
                {
                    this.Children = new List<Region>();
                }
                foreach (var item in value)
                {
                    this.Children.Add(item);
                }
            }
        }
    }
}
